﻿Option Explicit On
Option Strict On

Imports ACOMDirector.Framework.Configuration

Namespace Configuration

    Friend Class SystemConfiguration

#Region " Shared Members "

        Private Shared m_Singleton As SystemConfiguration

#End Region

#Region " Private Members "

        Private m_ConfigSource As XmlConfigSource
        Private m_ACOMConfiguration As ACOMConfiguration

#End Region

#Region " Constructor "

        ''' <summary>
        ''' Default constructor
        ''' </summary>
        ''' <remarks></remarks>
        Private Sub New()
            Dim ConfigFolder As String = Environment.GetFolderPath(Environment.SpecialFolder.ApplicationData) & "\YOM Systems\ACOM Director"
            Dim ConfigSource As String = ConfigFolder & "\ACOMDirector.Config.xml"

            If Not IO.Directory.Exists(ConfigFolder) Then
                IO.Directory.CreateDirectory(ConfigFolder)
            End If

            If Not IO.File.Exists(ConfigSource) Then
                m_ConfigSource = New ACOMDirector.Framework.Configuration.XmlConfigSource
                m_ConfigSource.Save(ConfigSource)
            Else
                m_ConfigSource = New ACOMDirector.Framework.Configuration.XmlConfigSource(ConfigSource)
            End If

            m_ACOMConfiguration = New ACOMConfiguration(m_ConfigSource)

        End Sub

#End Region

#Region " Shared Properties "

        ''' <summary>
        ''' The singleton instance of the configuration objects
        ''' </summary>
        ''' <value></value>
        ''' <returns></returns>
        ''' <remarks></remarks>
        Public Shared ReadOnly Property Instance() As SystemConfiguration
            Get
                If m_Singleton Is Nothing Then
                    m_Singleton = New SystemConfiguration
                End If

                Return m_Singleton
            End Get
        End Property

#End Region

#Region " Public Properties "

        ''' <summary>
        ''' The ACOM Director main configuration object
        ''' </summary>
        ''' <value></value>
        ''' <returns></returns>
        ''' <remarks></remarks>
        Public ReadOnly Property ACOMConfiguration() As ACOMConfiguration
            Get
                Return m_ACOMConfiguration
            End Get
        End Property

#End Region

#Region " Public Members "

        ''' <summary>
        ''' Saves the configuration
        ''' </summary>
        ''' <remarks></remarks>
        Public Sub Save()
            m_ConfigSource.Save()
        End Sub

#End Region

    End Class

End Namespace